package com.sykj.bsc.zn.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sykj.bsc.rwl.commons.ResponseCode;
import com.sykj.bsc.rwl.commons.ServerResponse;
import com.sykj.bsc.rwl.po.SysMenu;
import com.sykj.bsc.zjj.bean.Bis_shop_post;
import com.sykj.bsc.zn.bean.Bis_beauty_record;
import com.sykj.bsc.zn.bean.Bis_business_order;
import com.sykj.bsc.zn.bean.Bis_cash_record;
import com.sykj.bsc.zn.bean.Bis_shop;
import com.sykj.bsc.zn.bean.Bis_shop_user;
import com.sykj.bsc.zn.bean.FinanceUser;
import com.sykj.bsc.zn.controller.QtController;
import com.sykj.bsc.zn.mapper.znmapper;

@Service
public class znServiceImpl implements znService{

	@Autowired
	private znmapper sum;
	/**
	 * 商家
	 */

	@Override
	public List<Map> finduser_shop(Bis_shop_user shop_user) {
		return sum.finduser_shop(shop_user);
	}

	@Override
	public List<Map> findshop1(Bis_shop shop) {
		return sum.findshop1(shop);
	}


	@Override
	public void deleteshopuser1(String shop_user_id){
		sum.deleteshopuser1(shop_user_id);
	}

	@Override
	public void insertshop(Bis_shop shop) {
		sum.insertshop(shop);
	}


	@Override
	public Bis_shop_user toupdateshop(String shop_user_id){
		return sum.toupdateshop(shop_user_id);
	}

	@Override
	public void updateshopuser(Bis_shop_user shopuser) {
		sum.updateshopuser(shopuser);
	}

	@Override
	public void deleteshop(int shop_id){
		sum.deleteshop(shop_id);
	}

	@Override
	public Bis_shop toupdateshop2(int shop_id) {
		return sum.toupdateshop2(shop_id);
	}



	@Override
	public void insertshopuser(Bis_shop_user shopuser) {
		sum.insertshopuser(shopuser);
	}

	//修改密码
	@Override
	public void updatepassword(Bis_shop_user shopuser) {
		sum.updatepassword(shopuser);		
	}


	/**
	 * 财务
	 */

	@Override
	public List<Map> findcashrecord(Bis_cash_record cashrecord) {
		return sum.findcashrecord(cashrecord);
	}

	@Override
	public void deletecash(String record_id) {
		sum.deletecash(record_id);
	}

	@Override
	public List<Map> findbeautyrecord(Bis_beauty_record beaurtyrecord) {
		return sum.findbeautyrecord(beaurtyrecord);
	}



	@Override
	public Bis_business_order findbusinessorder() {
		return sum.findbusinessorder();
	}

	@Override
	public List<Map> findshopandorder(int shop_id) {
		return sum.findshopandorder(shop_id);
	}

	@Override
	public List<Map> findorderanduser(Bis_business_order order) {
		return sum.findorderanduser(order);
	}

	@Override
	public List<Map> findshopuserpostbusiness(Map map){
		return sum.findshopuserpostbusiness(map);
	}

	@Override
	public void updateshop (Bis_shop shop) {
		sum.updateshop(shop);
	}

	@Override
	public List<Map> findshop(Bis_shop shop) {
		return sum.findshop(shop);
	}

	@Override
	public List<Map> findproject() {
		return sum.findproject();
	}

	//导出excel
	@Override
	public List<Map<String, String>> cashexcel(Bis_cash_record cash ) {
		List<Map> list= sum.findcashrecord(cash);
		List<Map<String, String>> mapList=new ArrayList<Map<String,String>>();
		for (Map<String, String> bean_map : list) {
			Map<String, String> map=new HashMap<String, String>();
			map.put("流水号",  bean_map.get("record_id"));
			map.put("订单编号",  bean_map.get("order_id"));
			map.put("顾客账号", bean_map.get("custom_user_id"));
			map.put("姓名",  bean_map.get("username")+"");
			map.put("颜值数量",bean_map.get("beauty_num"));
			map.put("支付方式", (bean_map.get("pay_way")=="1"?"微信":"支付宝"));
			map.put("实际消费金额", bean_map.get("money"));
			map.put("支付时间", bean_map.get("pay_time"));
			mapList.add(map);
		}
		return mapList;
	}

	@Override
	public List<Map<String, String>> beautryrecordexcel(Bis_beauty_record beaurtyrecord) {
		List<Map> list= sum.findbeautyrecord(beaurtyrecord);
		List<Map<String, String>> mapList=new ArrayList<Map<String,String>>();
		for (Map<String, String> bean_map : list) {
			Map<String, String> map=new HashMap<String, String>();
			map.put("流水号",  bean_map.get("record_id"));
			map.put("订单编号",  bean_map.get("order_id"));
			map.put("顾客账号", bean_map.get("custom_user_id"));
			map.put("姓名",  bean_map.get("username")+"");
			map.put("颜值数量",bean_map.get("beauty_num"));
			map.put("实际消费金额", bean_map.get("total_money"));
			map.put("分类", (bean_map.get("record_type")=="1"?"购买颜值":bean_map.get("record_type")=="2"?"服务消费":"兑换颜值"));
			map.put("支付时间", bean_map.get("pay_time"));
			mapList.add(map);
		}
		return mapList;
	}

	@Override
	public List<Map<String, String>> shopexcel(Bis_shop shop) {
		List<Map> list= sum.findshop(shop);
		List<Map<String, String>> mapList=new ArrayList<Map<String,String>>();

		for (Map<String, String> bean_map : list) {
			Map<String, String> map=new HashMap<String, String>();
			map.put("店铺编号",  bean_map.get("shop_id"));
			map.put("店铺名称",  bean_map.get("shop_name"));
			map.put("店铺简称", bean_map.get("short_name"));
			map.put("店铺现金收入",  bean_map.get("cash_income"));
			map.put("现金收入目标业绩",bean_map.get("month_cash_in"));
			map.put("完成率", bean_map.get("a"));
			map.put("店铺消耗收入", bean_map.get("extend_income"));
			map.put("消耗收入目标业绩", bean_map.get("month_expend_in"));
			map.put("完成率", bean_map.get("b"));
			map.put("免费颜值收入", bean_map.get("free_num"));
			mapList.add(map);
		}
		return mapList;
	}

	@Override
	public List<Map<String, String>> orderanduserexcel(Bis_business_order order) {
		List<Map> list= sum.findorderanduser(order);
		List<Map<String, String>> mapList=new ArrayList<Map<String,String>>();
		for (Map<String, String> bean_map : list) {
			Map<String, String> map=new HashMap<String, String>();
			map.put("订单编号",  bean_map.get("order_id"));
			map.put("交易时间",  bean_map.get("pay_time"));
			map.put("顾客账号", bean_map.get("custom_user_id"));
			map.put("顾客姓名",  bean_map.get("username"));
			map.put("交易内容",bean_map.get("order_content"));
			map.put("价格(元)", bean_map.get("order_money"));
			map.put("实付金额(元)", bean_map.get("pay_money"));
			map.put("消耗颜值", bean_map.get("extend_beauty_num"));
			map.put("支付方式", (bean_map.get("pay_way")=="1"?"微信":bean_map.get("pay_way")=="2"?"支付宝":bean_map.get("pay_way")=="3"?"美颜币":"套餐"));
			map.put("现金收入(元)", bean_map.get("cash_income"));
			map.put("消耗收入(元)", bean_map.get("extend_income"));
			map.put("服务员工", bean_map.get("server_user_id"));
			map.put("经手员工", bean_map.get("handle_user_id"));
			mapList.add(map);
		}
		return mapList;
	}

	


	/**
	 * 创建人：池磊
	 * 用途：找店铺
	 * @return
	 */
	@Override
	public List<Bis_shop> selectBis_shop() {
		return sum.selectBis_shop();
	}
	/**
	 * 创建人：池磊
	 * 用途：根据id找店铺
	 * @return
	 */
	@Override
	public Bis_shop getBis_shopByid(String shop_id) {
		return sum.getBis_shopByid(shop_id);
	}	

	public String findAccount(String mobile) {
		String account=sum.findAccount(mobile);
		return account;
	}

	/**
	 * @Title: updatePssword   
	 * @Description:修改密码  
	 * @param: @return      
	 * @return: ServerResponse<String>      
	 * @throws
	 */
	public ServerResponse<String> updatePssword(String mobile,String password,String account){
		System.out.println(mobile+"0000");
		if(mobile==null || mobile.equals("") || password.equals("") || password==null) {
			return ServerResponse.createByError(ResponseCode.ILLEGAL_ARGUMENT.getCode(),"参数类型错误");
		}
		Object newpassword=QtController.Md5Encrypt(account, password);
		password=newpassword.toString();
		int resultCounnt=sum.updatePassword(password, mobile,account);
		if(resultCounnt==0) {
			return ServerResponse.createByError("修改失败");
		}
		return ServerResponse.createBySuccess("修改成功");
	}

	@Override
	public Bis_shop_user judgemobile(String mobile) {
		return sum.judgemobile(mobile);
	}

	@Override
	public List<Map> findQt(String shop_user_id) {
		HashMap<String, Object> map=new HashMap<>();
		map.put("shop_user_id", shop_user_id);
		return sum.findQt(map);
	}

	@Override
	public String findPost_name(String post_code) {
		return sum.findPost_name(post_code);
	}

	@Override
	public List<Bis_shop> findshop2() {
		return sum.findshop2();
	}

	//根据店铺id查询用户信息
	public List<SysMenu> findUserMenu() {
		return sum.find_Bis_shop_Post();
	}

	@Override
	public Map finddianmian(String shop_id) {
		return sum.finddianmian(shop_id);
	}

	//判断用户号码是否存在
	public boolean checkAccount(String account) {
		int resultCount=sum.checkAccount(account);
		if(resultCount>0) {
			return false;
		}
		return true;
	}

	//判断手机号码是否存在
	public boolean checkMobile(String mobile) {
		int resultCount=sum.checkMobile(mobile);
		if(resultCount>0) {
			return false;
		}
		return true;
	}

	@Override
	public List<Map> findshopuserBytype(String user_type) {
		return sum.findshopuserBytype(user_type);
	}

	//填充下拉框
	public List<Bis_shop_post> selectBis_shop_post(){
		return sum.selectBis_shop_post();
	}

	public List<Map> findQt2(String shop_id) {
		HashMap<String, Object> map=new HashMap<>();
		map.put("shop_id", shop_id);
		return sum.findQt(map);
	}

	@Override
	public List<Map> findbisinessordel(Bis_business_order businessorder) {
		return sum.findbisinessordel(businessorder);
	}

	@Override
	public Bis_business_order findgetorder(Map map) {
		return sum.findgetorder(map);
	}

	
	@Override
	public List<FinanceUser> listfinanceuser(Map map) {
		// TODO Auto-generated method stub
		return sum.listfinanceuser(map);
	}

	@Override
	public FinanceUser getfinanceuser(Map map) {
		// TODO Auto-generated method stub
		return sum.getfinanceuser(map);
	}


	
}
